package com.project.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.MtTicketBean;
import com.project.mapper.IMtTicketMapper;
import com.project.service.IMtTicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class MtTicketServiceImpl implements IMtTicketService {
    @Autowired
    private IMtTicketMapper mtTicketMapper;

    @Override
    public void add(String name,Integer price,Integer number) {
        mtTicketMapper.insert(new MtTicketBean(name,price,number));
    }

    @Override
    public IPage<MtTicketBean> mtTicketAll(Integer pageNO) {
        QueryWrapper<MtTicketBean>qw=new QueryWrapper<>();
        //对电影票数量大于0的进行拉取
        qw.gt("t_number",0);
        return mtTicketMapper.selectPage(new Page<>(pageNO,3),qw);
    }

    @Override
    public void updateNumber(Integer mtTicketId) {
        MtTicketBean mtTicket=mtTicketMapper.selectById(mtTicketId);
        int num=mtTicket.getNumber();
        num--;
        mtTicket.setNumber(num);
        mtTicketMapper.updateById(mtTicket);
    }
}
